// GameLogic.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <vector>
#include <common/alloc/auto_alloc.hpp>
#include "BoardFactory.h"
#include "Board.h"
#include "Field.h"
#include "Direction.h"
#include "BoardDisplayBase.h"


using namespace catan;

BoardFactory factory;
Handle<Board> board;
int p[20][20] = {0};
int found[19] = {0};
int findNum = 19;
int ct = 0;

void FindNext(int ct, int cx, int cy)
{
	int nx = 0;
	int ny = 0;
	if (findNum == 0)
	{
		return ;
	}
	Handle<Field> curField = board->mFields[ct];
	for (int i = FieldDirection::Start; i < FieldDirection::Num; ++i)
	{
// 		if(curField->mEdgeFields[i] && found[curField->mEdgeFields[i]->mId] == 0)
// 		{
// 			found[curField->mEdgeFields[i]->mId]  = 1;
// 			switch(i)
// 			{
// 			case FieldDirection::UpRight: nx = cx +1; ny = cy -1; break;
// 			case FieldDirection::Right: nx = cx + 2;ny=cy;break;
// 			case FieldDirection::DownRight: nx = cx +1; ny = cy +1;break;
// 			case FieldDirection::DownLeft: nx = cx -1; ny = cy + 1;break;
// 			case FieldDirection::Left: nx = cx - 2;ny =cy; break;
// 			case FieldDirection::UpLeft: nx = cx - 1; ny = cy-1;break;
// 			}
// 			p[ny][nx] = curField->mEdgeFields[i]->mId;
// 			findNum --;
// 			FindNext(p[ny][nx], nx, ny);
// 		}

	}
}
void TestConsoleBoardDisplay()
{
	Handle<Board> board = factory.Create4Board();
	BoardDisplayBase* dp = BoardDisplayBase::New();
	dp->Display(board);
}
void testout()
{
	board = factory.Create4Board();

	memset(p, -1, sizeof(p));
	
	found[ct] = true;
	p[0][2] = ct;
	--findNum;
	int cx = 2;
	int cy = 0;

	FindNext(ct, cx, cy);

	for (int i = 0; i < 20; ++i)
	{
		for (int j = 0; j < 20; ++j)
		{
			if (p[i][j] == -1)
			{
				printf("  ");
			}
			else
			{
				printf("%2d", p[i][j]);
			}
		}
		printf("\n");
	}
};
class A
{
public:
	A()
	{
		a =1;
	}
	~A()
	{
		a =0;
	}
	int a;
	static const float t;
};

A GetA()
{
	A a;
	return a;
}

template <class _Ty>
class Vector : public std::vector<_Ty>
{
public:
	void Begin()
	{
		mIter = this->begin();
	}
	_Ty& GetCur()
	{
		return *mIter;
	}
	void Next()
	{
		++mIter;
	}
	bool IsEnd()
	{
		return mIter == this->end();
	}
	typedef typename std::vector<_Ty>::iterator Iter;
	Iter mIter;
};
template< class Vec >
class VectorIter
{
public:
	VectorIter(Vec& vect)
		: mVect(vect)
	{
		mIt = mVect.begin();		
	}
	void operator++ ()
	{
		++mIt;
	}
	bool IsEnd()
	{
		return mIt == mVect.end();
	}

	bool Inc()
	{
		++mIt;
		return mIt != mVect; 
	}
	operator bool ()
	{
		return mIt != mVect.end();
	}

	typename Vec::value_type& operator *()
	{
		return *mIt;
	}
	typename Vec& mVect;
	typename Vec::iterator mIt;
	typedef typename Vec::value_type ValueType;
};

class P
{
public:
	int Do(int t)
	{
		int a = t;
		printf("Do");
		return 1;
	}
};



struct BasicStruct
{

	void Do(){}

int x;
	typedef int Ab;
 double y;
};
 

 
//BasicStruct var1{5, 3.2};


#define DoEach(vv, Fun) \
	std::for_each(vv.begin(), vv.end(), [](decltype(vv.front())& v) \
	{\
		v.Fun();\
	});

#define ElemType(X) decltype(X.front())
#define AllOf(X) X.begin(), X.end()
template<class _InIt,
	class _Fn1> inline
	_Fn1 ForAll(_InIt b, _Fn1 _Func)
	{	// perform function for each element
		return std::for_each(b.begin(), b.end(), _Func);
	}

	class AA
	{
	public:
		AA() : a(10){}
		void Do();
	protected:
		int a;
	};

	class B : public AA
	{
		public:
		int Get() {return AA::a;}
		int c;
	};

	

int _tmain(int argc, _TCHAR* argv[])
{
	//_tsetlocale( LC_ALL, _T("English" ));
	_tsetlocale( LC_ALL, _T("chs"));
	TestConsoleBoardDisplay();
	//testout();

// 	AA* aa = new AA();
// 	B* b = static_cast<B*>(aa);
// 	int tttt = b->Get();
// 	std::map<int,int> mp;
// 	std::vector<BasicStruct> basics;
// 	basics.push_back(BasicStruct());
// 	for(auto t = basics.begin(); t != basics.end(); ++t)
// 	{
// 		t->Do();
// 	}
// 	DoEach(basics, Do);
// 	BasicStruct bb;
// 	BasicStruct::Ab tt;
// 	ForAll(basics, [](decltype(*basics.begin())& b)
// 	{
// 		b.Do();
// 	});
// 
// 	ForAll(mp, [](decltype(*mp.begin())& b)
// 	{
// 		b.second = 1;
// 	});
// 
// 	std::for_each(AllOf(basics), [](ElemType(basics)& b)
// 	{
// 		b.Do();
// 	});
// 	
// 	for(auto t = basics.begin(); t != basics.end(); ++t)
// 	{
// 		t->Do();
// 	}
// 	Vector<int> vi;
// 	vi.push_back(1);
// 	for (vi.Begin(); !vi.IsEnd(); vi.Next())
// 	{
// 		int i = vi.GetCur();
// 	}
// 	std::vector<int> vv;
// 	vv.push_back(1);
//  	for (VectorIter<std::vector<int>> it(vv); it; ++it)
//  	{
//  		int i = *it;
//  	}
// 
// 	A& a = GetA();

	
	return 0;
}

